package com.xwb.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xwb.dao.ScoreDao;
import com.xwb.domain.Score;
import com.xwb.service.ScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/Scores")
public class ScoreController {
    @Autowired
    private ScoreService scoreService;
    @Autowired
    private ScoreDao scoreDao;

    /**
     * 该方法可以得到成绩的降序排名
     */
    @GetMapping
    public Result getWorkRank() {

        QueryWrapper<Score> qm = new QueryWrapper<>();
        qm.orderByDesc("final_score");
        List<Score> scores = scoreDao.selectList(qm);
        System.out.println(scores);

        Integer code = scores != null ? Code.GET_OK : Code.GET_ERR;
        String msg = scores != null ? "这是成绩的排名顺序" : "数据查询失败，请重试";

        return new Result(code, scores, msg);
    }


}
